import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home.vue'

Vue.use(VueRouter)

const routes = [{
        path: '/',
        redirect: "/home"
    },
    // {
    //     path: '/about',
    //     name: 'About',
    //     // route level code-splitting
    //     // this generates a separate chunk (about.[hash].js) for this route
    //     // which is lazy-loaded when the route is visited.
    //     component: () =>
    //         import ( /* webpackChunkName: "about" */ '../views/About.vue')
    // },
    {
        path: '/home',
        name: 'home',
        component: () =>
            import ('../views/home/index.vue')
    },
    {
        path: '/home/city',
        name: 'city',
        component: () =>
            import ('../views/home/city/index.vue')
    },
    {
        path: '/home/search',
        name: 'search',
        component: () =>
            import ('../views/home/search/index.vue')
    },
    {
        path: '/home/brandinfo',
        name: 'brandinfo',
        component: () =>
            import ('../views/home/brand/index.vue')
    },
    {
        path: '/home/news',
        name: 'news',
        component: () =>
            import ('../views/home/news/index.vue')
    },
    {
        path: '/home/hot',
        name: 'hot',
        component: () =>
            import ('../views/home/hot/index.vue')
    },
    {
        path: '/home/cate',
        name: 'cate',
        component: () =>
            import ('../views/home/cate/index.vue')
    },
    {
        path: '/home/goods',
        name: 'goods',
        component: () =>
            import ('../views/home/goods/index.vue')
    },
    {
        path: '/topic',
        name: 'topic',
        component: () =>
            import ('../views/topic/index.vue')
    },
    {
        path: '/topic/details',
        name: 'details',
        component: () =>
            import ('../views/topic/details/index.vue')
    },
    {
        path: '/category',
        name: 'category',
        component: () =>
            import ('../views/category/index.vue')
    },
    {
        path: '/cart',
        name: 'cart',
        component: () =>
            import ('../views/cart/index.vue')
    },
    {
        path: '/cart/order',
        name: 'order',
        component: () =>
            import ('../views/cart/order/index.vue')
    },
    {
        path: '/my',
        name: 'my',
        component: () =>
            import ('../views/my/index.vue')
    },
    {
        path: '/my/feedback',
        name: 'feedback',
        component: () =>
            import ('../views/my/feedback/index.vue')
    },
    {
        path: '/my/address',
        name: 'addresss',
        component: () =>
            import ('../views/my/Add/index.vue')
    },
    {
        path: '/my/address/change',
        name: 'change',
        component: () =>
            import ('../views/my/Add/changeAdd.vue')
    },
    {
        path: '/my/collection',
        name: 'collection',
        component: () =>
            import ('../views/my/collection/index.vue')
    },

]



const router = new VueRouter({
    routes,
    scrollBehavior(to, from, savePosition) { // 在点击浏览器的“前进/后退”，或者切换导航的时候触发。
        console.log(to) // to：要进入的目标路由对象，到哪里去
        console.log(from) // from：离开的路由对象，哪里来
        console.log(savePosition) // savePosition：会记录滚动条的坐标，点击前进/后退的时候记录值{x:?,y:?}
        if (savePosition) {
            return savePosition;
        } else {
            return { x: 0, y: 0 }
        }
    }

})


export default router